include $(TOPDIR)/rules.mk

PKG_NAME:=clitransfer
PKG_VERSION:=2017-01-18-1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://gitee.com/insk/clitransfer.git
PKG_SOURCE_PROTO:=git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=master
PKG_BUILD_DIR:=$(BUILD_DIR)/clitransfer-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk


define Package/clitransfer
  SECTION:=base
  CATEGORY:=Utilities
  DEFAULT:=y
  TITLE:=probe wifi client
  URL:=http://wirelesser.net/
  DEPENDS:= +libradiotap +libpthread +libopenssl +libpcap +libcurl +libxcjson
endef

define Package/clitransfer/config
        source "$(SOURCE)/Config.in"
endef

define Package/clitransfer/description
	probe wifi transfer 
endef


ifeq ($(CONFIG_POST_TO_WDAO),y)
POST_TYPE=WDAO
endif

ifeq ($(CONFIG_POST_TO_RZX),y)
POST_TYPE=RZX
endif

ifeq ($(CONFIG_NOT_POST),y)
POST_TYPE=NO
endif


define Build/Configure
	(cd $(PKG_BUILD_DIR); \
		CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
		CXXFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
		LDFLAGS="$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS)" \
		cmake \
			-DIN_OPENWRT=1 \
			-DCMAKE_SYSTEM_NAME=Linux \
			-DCMAKE_SYSTEM_VERSION=1 \
			-DCMAKE_SYSTEM_PROCESSOR=$(ARCH) \
			-DCMAKE_BUILD_TYPE=Release \
			-DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
			-DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
			-DCMAKE_C_COMPILER="$(CMAKE_C_COMPILER)" \
			-DCMAKE_C_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
			-DCMAKE_CXX_COMPILER="$(CMAKE_CXX_COMPILER)" \
			-DCMAKE_CXX_COMPILER_ARG1="$(CMAKE_CXX_COMPILER_ARG1)" \
			-DCMAKE_EXE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
			-DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
			-DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
			-DCMAKE_AR="$(CMAKE_AR)" \
			-DCMAKE_RANLIB="$(CMAKE_RANLIB)" \
			-DCMAKE_FIND_ROOT_PATH="$(STAGING_DIR);$(TOOLCHAIN_DIR)" \
			-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
			-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
			-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
			-DCMAKE_STRIP=: \
			-DCMAKE_INSTALL_PREFIX=/usr \
			-DDL_LIBRARY=$(STAGING_DIR) \
			-DCMAKE_PREFIX_PATH=$(STAGING_DIR) \
			$(CMAKE_OPTIONS) \
		$(CMAKE_SOURCE_DIR) \
	)
endef



define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR)
endef
#	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/clitransfer $(1)/usr/sbin/

define Package/clitransfer/install
	$(INSTALL_DIR) $(1)/usr/sbin/
	$(INSTALL_DIR) $(1)/usr/sbin/anywifi/
	$(INSTALL_DIR) $(1)/etc/
	$(INSTALL_DIR) $(1)/etc/config/
	$(INSTALL_DIR) $(1)/etc/init.d/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/transfer/transfer $(1)/usr/sbin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/transfer/post_info_$(POST_TYPE).sh $(1)/usr/sbin/post_info.sh
	$(INSTALL_DATA) $(PKG_BUILD_DIR)/transfer/clitransfer.cfg $(1)/etc/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/transfer/clitransfer.uci $(1)/etc/config/clitransfer
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/transfer/clitransfer.init $(1)/etc/init.d/clitransfer
	$(INSTALL_DATA) $(PKG_BUILD_DIR)/transfer/probe_$(POST_TYPE) $(1)/etc/probe
	#$(CP) -r $(PKG_BUILD_DIR)/client/scripts/* $(1)/usr/sbin/
	if [ $(CONFIG_CTLCLI) == "ON" ]; then \
		$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/control/clictlser $(1)/usr/sbin/; \
		fi
endef

$(eval $(call BuildPackage,clitransfer))
